package emulator.hardware.nmos6502.commands;

import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.nmos6502.Command;
import emulator.hardware.nmos6502.CommandSet;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Operand;
import emulator.hardware.nmos6502.operands.*;

/**	AXS    ***    (SAX)
 *	AXS ANDs the contents of the A and X registers (without changing the 
 *	contents of either register) and stores the result in memory.
 *	AXS does not affect any flags in the processor status register.
 *	
 *	Supported modes:
 *	
 *	AXS abcd        ;8F cd ab    ;No. Cycles= 4
 *	AXS ab          ;87 ab       ;            3
 *	AXS ab,Y        ;97 ab       ;            4
 *	AXS (ab,X)      ;83 ab       ;            6
 *	
 *	(Sub-instructions: STA, STX)
 *	
 *	Example:
 *	
 *	AXS $FE         ;87 FE
 *	
 *	Here's the same code using equivalent instructions.
 *	
 *	STX $FE
 *	PHA
 *	AND $FE
 *	STA $FE
 *	PLA
 */
public class AXS implements Command {

	@Override
	public void execute(Cpu6502 cpu, Operand operand) throws EmulatorException {
		HwByte value = cpu.getAccu();
		value.and(cpu.getX());
		operand.setByte(value);
	}

	@Override
	public String getName() {
		return "AXS";
	}

	@Override
	public void register(CommandSet cset) {
		cset.defineCommand(0x8F, this, new Absolute());
		cset.defineCommand(0x87, this, new ZeroPage());
		cset.defineCommand(0x97, this, new ZeroPageY());
		cset.defineCommand(0x83, this, new IndirectX());
	}

}
